<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="~/MainSys/Manager/Controls/ctManagementTrainning.ascx.cs" Inherits="KhoaLuan.MainSys.Manager.Controls.ctManagementTrainning" %>
<link href="../../../Style/StyleCommon.css" rel="stylesheet" />
<link href="../../../Style/modal.css" rel="stylesheet" />
<script src="/Scripts/dluscript.js"></script>
<script type="text/javascript">
    var currentTraining;
    var _listTraining = [];

    function GetTrainingInList(idTraining) {
        for (var i = 0; i < _listTraining.length; i++) {
            if (_listTraining[i].id == idTraining)
                return _listTraining[i];
        }
        return null;
    }
    ///
  
    function EditNganhDaoTao(
        id,
        TenNganh,
        MaNganh,
        BacHoc,
        HeDaoTao,
        GioiThieu,
        OrgID) {
        $('#<%=txtid.ClientID%>').val(id);
            $('#<%=txtTenNganh.ClientID%>').val(TenNganh);
        $('#<%=txtMaNganh.ClientID%>').val(MaNganh);
        $('#<%=txtBacHoc.ClientID%>').val(BacHoc);
        $('#<%=txtHeDaoTao.ClientID%>').val(HeDaoTao);
        $('#<%=txtGioiThieu.ClientID%>').val(GioiThieu);
        $('#<%=dllOrgIDEd.ClientID %>').val(OrgID);
        $('#titleoverlay').text("Cap Nhat");
        $('#rowID').hide();
        $('#<%=btnThemMoi.ClientID%>').hide();
        $('#<%=btnCapNhat.ClientID%>').show();
        overlay('1');
    }

    function LoadListTraining(totalitem, target, listTraining) {
        _listTraining = listTraining;
        debugger;
        target.empty();
        _listTraining.forEach(function (item) {
            var tr = $("<tr>");
            var td = $("<td>").append($('<input type="checkbox">'));
            tr.append(td);
            td = $("<td>").text(item.TenNganh);
            tr.append(td);
            td = $("<td>").text(item.MaNganh);
            tr.append(td);
            td = $("<td>").text(item.BacHoc);
            tr.append(td);
            td = $("<td>").text(item.HeDaoTao);
            tr.append(td);
            td = $("<td>");
            var btnedit = CreateButton(item.id, "fa-edit");
            btnedit.click(function () {
                currentTraining = GetTrainingInList($(this).attr('dataid'));
                var target = "/MainSys/Manager/Department/AddNewTraining.aspx";
                $('#remoteModal').removeData();
                $("#remoteModal").load(target, function () {
                    $("#remoteModal").modal("show");
                });
            });
            td.append(btnedit);
            var btndel = CreateButton(item.id, "fa-times");
            btndel.click(function () {
                debugger;
                var id = $(this).attr("dataid");
                var sender = $(this);
                confirm("Xác nhận", "Bạn có muốn xóa ngành đào tạo này không", "Xóa", "Hủy bỏ", function () {
                    debugger;
                    CallAjaxAspx("POST", "DeleteNganhDaoTao", "/MainSys/ProcessAJAX/AjaxDepartment.aspx", { id: parseInt(id) }, function (data) {
                        debugger;
                        var responseDel = JSON.parse(data);

                        if (responseDel.Status) {
                            debugger;
                            sender.parent().parent().remove();
                            alertSmallBox("Xóa ngành đào tạo thành công", "1 giây trước...");
                        }
                        else {
                            alertSmallBox("Xóa ngành đào tạo thất bại", "1 giây trước...", "error");
                        }
                    }, function () { }, function () { });
                });
            });
            debugger;
            td.append(btndel);
            tr.append(td);
            target.append(tr);
        });
    }

    function LoadData(page) {
        debugger;
        var numberinpage = 5;
        var keyword = $("#<%=txtTimKiem.ClientID%>").val();
        var dataagr = JSON.stringify({
            keyword: keyword,
            currentpage: parseInt(page),
            numberinpage: numberinpage
        });
        LoadDataWithPaging($("#tableNganhDaoTao > tbody"), $("#divpaging"), page, "POST", "/MainSys/ProcessAJAX/AjaxDepartment.aspx/GetListNganhDaoTao", dataagr, LoadListTraining, numberinpage, LoadData);
    }
        
    $(document).ready(function () {
        debugger;
        LoadData(1);
        $("#<%=btnThem.ClientID%>").click(function () {
            currentTraining = null;
            var target = "/MainSys/Manager/Department/AddNewTraining.aspx";
            $('#remoteModal').removeData();
            $("#remoteModal").load(target, function () {
                $("#remoteModal").modal("show");
            });
        });
    });
          
    function Import() {
        debugger;
        var datafile = new FormData();
        var files = $("#fileUpload").get(0).files;
        //// Add the uploaded image content to the form data collection
        if (files.length > 0) {
            datafile.append("File", files[0]);
        }
        datafile.append("TableName", "NganhDaoTao");

        // Make Ajax request with the contentType = false, and procesDate = false
        $.ajax({
            type: "POST",
            url: "/ProcessAJAX/AJAXImport.ashx",
            contentType: false,
            processData: false,
            data: datafile,
            success: function (data) {
                var res = JSON.parse(data);
                if (res.Status == "Success") {
                    alert("import thành công.");
                    LoadTableNganhDaoTao();
                }
                else {
                    alert("import thất bại.");
                }
            }
        });

    }

</script>

<div class="jarviswidget jarviswidget-color-blueDark" id="wid-id-1" data-widget-editbutton="false" data-widget-fullscreenbutton="false">


    <header>
        <h2>Manage Training	</h2>
        <div class="widget-toolbar">
            <!-- add: non-hidden - to disable auto hide -->

            <div class="btn-group">
                <input class="btn btnthem dropdown-toggle btn-xs btn-success" type="button" id="btnThem" runat="server" style="margin-right: 10px;" value="Add new" />
                <input type="button" value="Show" class="btn btnthem dropdown-toggle btn-xs btn-success" onclick="LoadData(1)" />
            </div>
        </div>
    </header>
    <div>
        <div class="widget-body widget-hide-overflow padding">
            <div class="col-xs-12 col-sm-6">
                <div id="datatable_tabletools_filter" class="dataTables_filter">
                    <label style="float: left">
                        <span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
                        <input type="search" class="form-control" placeholder="input keyword" id="txtTimKiem" runat="server" />
                         <input type="button" onclick="LoadData(1);" value="Search" class="btn btn-default" style="width: 80px;" />
                    </label>
                </div>
            </div>
            <div class="col-sm-6 col-xs-6 hidden-xs" style="text-align: right;">
                <input type="file" id="fileUpload" accept="image/jpg" class="btn btn-default" />
                <input type="button" id="Button3" runat="server" onclick="Import()" value="import" class="btn btn-default" />
            </div>
            <asp:Label ID="Label2" runat="server" ForeColor="Red"></asp:Label>
            <table id="tableNganhDaoTao" class="table table-bordered">
                <thead>
                    <tr>
                        <td></td>
                        <td>Name of Training
                        </td>
                        <td>Code of Training
                        </td>
                        <td>
                            Degree
                        </td>
                        <td>training system
                        </td>
                        <td>Action
                        </td>
                    </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
            </div>
            <div id="divpaging"></div>
        </div>
    </div>

    <div id="overlay">
        <div class="backgroundoverlay"></div>
        <div class="contentoverlay" style="width: 500px;">
            <div class="headeroverlay">
                <div style="float: right; cursor: pointer" onclick="overlay(0);">X</div>
                <div id="titleoverlay">Add new</div>
            </div>
            <div class="bodyoverlay">
                <fieldset>
                    <table id="Table2">
                        <tr id="rowID">
                            <td>
                                <asp:Label ID="Label1" runat="server" Text="id"></asp:Label>
                            </td>
                            <td>
                                <asp:TextBox ID="txtid" runat="server" Style="width: 100%;"></asp:TextBox>
                                <asp:Label ID="lblerror" runat="server" ForeColor="Red"></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td>Name of training </td>
                            <td>
                                <asp:TextBox ID="txtTenNganh" runat="server" Visible="true" Width="200px" Style="width: 100%;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Code of training </td>
                            <td>
                                <asp:TextBox ID="txtMaNganh" runat="server" Visible="true" Width="200px" Style="width: 100%;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Degree </td>
                            <td>
                                <asp:TextBox ID="txtBacHoc" runat="server" Visible="true" Width="200px" Style="width: 100%;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>training system </td>
                            <td>
                                <asp:TextBox ID="txtHeDaoTao" runat="server" Visible="true" Width="200px" Style="width: 100%;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td>Introduce </td>
                            <td>
                                <asp:TextBox ID="txtGioiThieu" runat="server" Visible="true" Width="200px" Style="width: 100%;"></asp:TextBox>
                            </td>
                        </tr>
                        <tr>
                            <td style="width: 150px">organization</td>
                            <td style="width: 150px">
                                <asp:DropDownList ID="dllOrgIDEd" runat="server" Style="width: 100%;">
                                </asp:DropDownList></td>
                            <td>
                        </tr>
                    </table>
                    <input type="button" id="btnBack" class="them" onclick="overlay('0')" value="Back" />
                    <input type="button" id="btnThemMoi" runat="server" class="them" onclick="overlay(0);" value="Add new" />
                    <input type="button" id="btnCapNhat" runat="server" class="them" onclick="overlay(0);" value="Update" />
                </fieldset>
            </div>
        </div>
    </div>
</div>

